package com.example.transaction.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.transaction.sys.entity.Item;
import com.example.transaction.sys.entity.User;
import com.example.transaction.sys.mapper.ItemMapper;
import com.example.transaction.sys.mapper.UserMapper;
import com.example.transaction.sys.service.IItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zh
 * @since 2023-06-20
 */
@Service
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements IItemService {

    private final ItemMapper itemMapper; // 假设使用MyBatis Plus的Mapper接口

    public ItemServiceImpl( ItemMapper itemMapper) {
        this.itemMapper = itemMapper;
    }
    @Override
    public List<Integer> getItemIdsByItemNameLike(String itemName) {
        LambdaQueryWrapper<Item> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Item::getItemName, itemName);
        List<Item> itemList = itemMapper.selectList(wrapper);
        return itemList.stream()
                .map(Item::getItemID)
                .collect(Collectors.toList());
    }
}
